const action = {
    enterFullscreen() {
        const element = document.documentElement;
        if (element.requestFullscreen) {
            element.requestFullscreen();
        } else if (element.webkitRequestFullscreen) {
            element.webkitRequestFullscreen();
        } else if (element.mozRequestFullscreen) {
            element.mozRequestFullscreen();
        } else if (element.msRequestFullscreen) {
            element.msRequestFullscreen();
        }
    },
    exitFullscreen() {
        if (document.exitFullscreen) {
            document.exitFullscreen();
        } else if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
        }
    },
    isImageFile: (name) => {
        if (!name) {
            return false
        } else {
            let p = name.toLowerCase()
            return p.endsWith('.jpg') || p.endsWith('.png') || p.endsWith('.jpeg') || p.endsWith('.bmp') || p.endsWith('.webp')
        }
    }
}

export const isImageFile = (name) => {
    if (!name) {
        return false
    } else {
        let p = name.toLowerCase()
        return p.endsWith('.jpg') || p.endsWith('.png') || p.endsWith('.jpeg') || p.endsWith('.bmp') || p.endsWith('.webp')
    }
}

export const isTextFile = (name) => {
    if (!name) {
        return false
    } else {
        let p = name.toLowerCase()
        return p.endsWith('.txt')
    }
}

export const isVideoFile = (name) => {
    if (!name) {
        return false
    } else {
        let p = name.toLowerCase()  // || p.endsWith('.mkv') || p.endsWith('.avi') || p.endsWith('.flv')
        return (
            // html5 默认格式
            p.endsWith('.mp4') ||
            p.endsWith('.webm') ||
            p.endsWith('.ogg') ||
            // ios 额外格式
            p.endsWith('.mov') ||
            // android 额外格式
            p.endsWith('.3gp')
        )
    }
}

export const fileSizeFormatted = (size = 0) => {
    if (size > (1024 * 1024 * 1024)) {
        return (size / (1024 * 1024 * 1024)).toFixed(2) + ' G'
    } else if (size > (1024 * 1024)) {
        return (size / (1024 * 1024)).toFixed(2) + ' M'
    } else if (size > (1024)) {
        return (size / (1024)).toFixed(2) + ' k'
    } else {
        return size + ' b'
    }
}

export const getWebPageProt = () => {
    let port = window.location.port;
    if (port === "") {
        if (window.location.protocol === "https:") {
            port = "443";
        } else if (window.location.protocol === "http:") {
            port = "80";
        }
    }
    return port
}